package org.exteen.tag.core;

import org.exteen.ExteenException;
import org.exteen.exec.ExteenContext;
import org.exteen.exec.ExteenPathChangeException;
import org.exteen.exec.Tag;
import org.exteen.exec.ExteenPathChangeException.Type;
import org.exteen.output.ExteenStream;

public class LoopInterruptingTag extends Tag {

    private final ExteenPathChangeException.Type type;

    public LoopInterruptingTag(Type type) {
        this.type = type;
    }

    public void doTag(ExteenContext ctx, ExteenStream stream) {
        Tag p = ctx.findParentTagOfType(ForEachTag.class);
        if (p==null) {
            throw new ExteenException("Tag " + ctx.getNode().getTag() + " must be placed inside forEach tag");
        }
        throw new ExteenPathChangeException(type);
    }
}